home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_12_11
/
phillip2
/
pattern.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-24
|
7KB
|
279 lines
/***********************************************
*
* file d:\cips\pattern.c
*
* Functions: This file contains
* main
*
* Purpose:
* I use this program to create simple
* patterns in images for illustrations.
*
* External Calls:
* gpcips.c - my_clear_text_screen
* wtiff.c - create_allocate_tiff_file
* write_array_into_tiff_image
*
* Modifications:
* 31 March 1991 - created
* 17 May 1993 - made this a command
* line driven program.
*
***********************************************/
#include "cips.h"
#undef STUFF
short out_image[ROWS][COLS];
main(argc, argv)
int argc;
char *argv[];
{
int count, i, ie, il, j, le, l, ll,
new_ie, new_il, w;
struct tiff_header_struct image_header;
my_clear_text_screen();
if(argc < 4 || argc > 4){
printf("\n usage: pattern file-name "
"length width\n"
"\n the program will multiply length "
"and width"
"\n by %d and %d", ROWS, COLS);
exit(-1);
}
l = atoi(argv[2]);
w = atoi(argv[3]);
image_header.lsb = 1;
image_header.bits_per_pixel = 8;
image_header.image_length = l*ROWS;
image_header.image_width = w*COLS;;
image_header.strip_offset = 1000;
create_allocate_tiff_file(argv[1], &image_header,
out_image);
new_ie = 1;
new_il = 1;
il = 1;
ie = 1;
ll = ROWS+1;
le = COLS+1;
/* make a rectangle */
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( i>=10 && i<=90 && j>=10 && j<=90)
out_image[i][j] = 0;
else
out_image[i][j] = 200;
}
}
count = 1;
for(i=0; i<l; i++){
for(j=0; j<w; j++){
printf("\nRunning %d of %d", count, l*w);
count++;
write_array_into_tiff_image(argv[1], out_image,
new_il + i*ROWS,
new_ie + j*COLS,
new_il + i*ROWS + ROWS,
new_ie + j*COLS + COLS);
}
}
} /* ends main */
#ifdef STUFF
/*
The following are samples patterns you can stick
into the output image.
*/
/* make a step pattern of gray shades */
for(i=0; i<ROWS; i++)
for(j=0; j<COLS; j++)
out_image[i][j] = 0;
for(i=0; i<ROWS; i++)
for(j=10; j<20; j++)
out_image[i][j] = 5;
for(i=0; i<ROWS; i++)
for(j=20; j<30; j++)
out_image[i][j] = 10;
for(i=0; i<ROWS; i++)
for(j=30; j<40; j++)
out_image[i][j] = 20;
/* make a club to look at thinning and mat */
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( i>4 && i<11 && j>4 && j<17)
out_image[i][j] = 200;
else
out_image[i][j] = 0;
}
}
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( i>1 && i<17 && j>4 && j<11)
out_image[i][j] = 200;
}
}
/* make a rectangle with a hole in it */
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( i>=5 && i<=8 && j>=5 && j<=18)
out_image[i][j] = 200;
}
}
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( i>=15 && i<=18 && j>=5 && j<=18)
out_image[i][j] = 200;
}
}
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( j>=5 && j<=8 && i>=5 && i<=18)
out_image[i][j] = 200;
}
}
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( j>=15 && j<=18 && i>=5 && i<=18)
out_image[i][j] = 200;
}
}
/* make the entire area white with a black hole
in it good for interior outline */
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( i>=10 && i<=15 && j>=10 && j<=18)
out_image[i][j] = 0;
else
out_image[i][j] = 200;
}
}
/* make a square */
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( i>=8 && i<=18 && j>=8 && j<=18)
out_image[i][j] = 200;
else
out_image[i][j] = 0;
}
}
/* make a square with a hole in
it for closing practice */
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( i>=8 && i<=13 && j>=8 && j<=13)
out_image[i][j] = 200;
else
out_image[i][j] = 0;
}
}
out_image[10][10] = 0;
out_image[11][10] = 0;
/* make 2 small squares
illustrate closing and special closing */
for(i=0; i<ROWS; i++)
for(j=0; j<COLS; j++)
out_image[i][j] = 0;
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( i>=8 && i<=13 && j>=8 && j<=9)
out_image[i][j] = 200;
if( i>=8 && i<=13 && j>=11 && j<=13)
out_image[i][j] = 200;
}
}
/* make a rectangle */
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( i>=8 && i<=18 && j>=4 && j<=18)
out_image[i][j] = 200;
else
out_image[i][j] = 0;
}
}
/* make a block letter A */
for(i=0; i<ROWS; i++)
for(j=0; j<COLS; j++)
out_image[i][j] = 0;
for(i=0; i<ROWS; i++)
for(j=0; j<COLS; j++)
if(i>=10 && i<=20 && j>=10 && j<=50)
out_image[i][j] = 200;
for(i=0; i<ROWS; i++)
for(j=0; j<COLS; j++)
if(i>=40 && i<=50 && j>=10 && j<=50)
out_image[i][j] = 200;
for(i=0; i<ROWS; i++)
for(j=0; j<COLS; j++)
if(i>=10 && i<=90 && j>=10 && j<=20)
out_image[i][j] = 200;
for(i=0; i<ROWS; i++)
for(j=0; j<COLS; j++)
if(i>=10 && i<=90 && j>=40 && j<=50)
out_image[i][j] = 200;
/* make a broken line */
for(i=0; i<ROWS; i++)
for(j=0; j<COLS; j++)
out_image[i][j] = 0;
for(i=0; i<ROWS; i++)
for(j=0; j<COLS; j++)
if(i>=10 && i<=11 && j>=5 && j<=18)
out_image[i][j] = 200;
out_image[10][11] = 0;
out_image[11][11] = 0;
/* make two squares joined together */
for(i=0; i<ROWS; i++)
for(j=0; j<COLS; j++)
out_image[i][j] = 0;
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( i>=5 && i<=15 && j>=5 && j<=9)
out_image[i][j] = 200;
if( i>=5 && i<=15 && j>=12 && j<=17)
out_image[i][j] = 200;
}
}
out_image[10][10] = 200;
out_image[10][11] = 200;
#endif